import axios from 'axios'
import { BASE_URL, TIME_OUT } from '../config'

class HYRequest {
  instance: any
  constructor(baseURL: string, timeout: number) {
    this.instance = axios.create({
      baseURL,
      timeout,
    })
    this.instance.interceptors.response.use(
      (res: { data: any }) => {
        return res.data
      },
      (err: any) => {
        return err
      }
    )
  }

  request(config: any) {
    return this.instance.request(config)
  }
  get(config: any) {
    return this.request({ ...config, method: 'get' })
  }
  post(config: any) {
    return this.request({ ...config, method: 'post' })
  }
}

const Request = new HYRequest(BASE_URL, TIME_OUT)
export default Request
